SRC = source
CC = gcc
AS = as
LD = ld
CFLAGS = -fno-builtin -fno-stack-protector -Iinclude
NAME = kernel.elf
C_OBJECTS = kernel.o stdio.o info.o gdt.o
S_OBJECTS = boot.so
LD_SCRIPTS = ldscript/kernel.ld

all: $(NAME) 

$(NAME): info $(C_OBJECTS) $(S_OBJECTS)
	cd build && $(LD) -o ../bin/$(NAME) $(S_OBJECTS) $(C_OBJECTS) -T ../$(LD_SCRIPTS)

%.o: $(SRC)/%.c
	@$(CC) $(CFLAGS) -o build/$@ -c $?
	@echo '$(CC) -c $?'

%.so: $(SRC)/%.S
	@$(CC) $(CFLAGS) -o build/$@ -c $?
	@echo '$(CC) -c $?'

clean: 
	@rm -v *.o
	@rm -v *.so
	@rm -v $(NAME)

run: $(NAME)
	cp bin/$(NAME) ../grub/fda
	sync
	qemu -fda ../grub/grub.i386.fd.img -fdb ../grub/fda.img

rebuild: clean all

info:
#	@echo '[01;34m-- build started --[0m'
	@echo $(CFLAGS)

